﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Filter;
using System.Linq.Expressions;
using COFE.Data.Utils.ThirdParty;

namespace COFE.Data.Filter
{
    public class GuidEntryFilterExpression :
         EntryFilterExpression<COFE.Core.Filter.GuidEntryFilter>
    {
        public GuidEntryFilterExpression()
            : base()
        {

        }

        public override Expression<Func<Entry, bool>> getExpression(
           IEntryFilter filter, IOptionFilter[] options)
        {
            var entryFilter = filter as COFE.Core.Filter.GuidEntryFilter;
            Expression<Func<Entry, bool>> exp = null;
            foreach (var g in entryFilter.LookupGuids)
                if (exp == null)
                    exp = e => e.EntryId == g;
                else exp = exp.Or(e => e.EntryId == g);
            if (filter.Negative)
                return exp.Not();
            return exp;
        }

    }
}
